import React from 'react'
import './index.css'
import PubSub from 'pubsub-js';
export default function Item({todo}) {
    // 删除当前数据
    function delTodo(id) {
        if(!window.confirm('确定删除吗？')) return 
        PubSub.publish('delTodo', id)
    }
    // 改变某个输入框的状态
    function changeOne(id) {
        PubSub.publish('checkOne', id)
    }
    return (
        <li>
            <label>
                <input type="checkbox" checked={todo.isDone} onChange={()=> changeOne(todo.id)}/>
                <span>{todo.title}</span>
            </label>
            <button className="btn btn-danger" onClick={() => delTodo(todo.id)}>删除</button>
        </li>
    )
}
